package com.abc.invoke.server;

import org.apache.catalina.startup.Tomcat;

import com.abc.invoke.server.service.AccessControlManager;
import com.abc.invoke.server.service.Nexus;
import com.abc.invoke.services.interfaces.AccessControlInterface;

public class SpringInvokerServer {
	private static Tomcat tomcat = null;

	private static String CONTEXT_PATH = "/client_service";//编译后的文件存放路径，也是服务的路径
	private static String BASE_PATH = System.getProperty("user.dir");
	private static String TOMCAT_HOME = BASE_PATH + "/appserver";
	private static String WEB_APP_PATH = BASE_PATH + "/appserver/webapps/client_service";

	private static String ENCODING = "UTF-8";
	private static int TOMCAT_PORT = 8080;

	// 启动嵌入式Tomcat服务器
	public static void startTomcat() throws Exception {

		Nexus nexus=new Nexus();
		AccessControlInterface aci=new AccessControlManager(nexus).getAci();
		
		long startTime = System.currentTimeMillis();

		tomcat = new Tomcat();
		// 设置Tomcat的工作目录:工程根目录/appserver
		tomcat.setBaseDir(TOMCAT_HOME);
		tomcat.setPort(TOMCAT_PORT);
		tomcat.addWebapp(CONTEXT_PATH, WEB_APP_PATH);
		tomcat.enableNaming();// 执行这句才能支持JDNI查找
		tomcat.getConnector().setURIEncoding(ENCODING);

		tomcat.start();
		System.err.println("Tomcat started in " + (System.currentTimeMillis() - startTime) + " ms.");
		tomcat.getServer().await();// 让服务器一直跑
		
		
	}

	public static void main(String[] args) {
		try {
			SpringInvokerServer.startTomcat();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}